angular.module('activities', [
  'ui.router'
  'activities.services'
  'activities.config_services'
  'activities.modal_services'
  'activities.controllers'
  'activities.filters'
  # '-activities.wechat_services'
])
.run ($rootScope) ->
  $rootScope.loading = true
  return

.directive 'scrollTo', ($window)->
  $win = angular.element($window)
  {
    restrict: 'A',
    link: (scope, element, attrs)->
      idToScroll = attrs.href
      top = $(idToScroll).offset().top
      root = $('#activity-double-twelve-page')
      element.click ()->  
        console.log top
        event.preventDefault()
        root.animate(scrollTop: top + 180)      
  }

.directive 'loading', ()->
  {
    restrict: 'A',
    replace:true,
    template: '<div class="loading">LOADING...</div>',
    link: (scope, element, attr) ->
      scope.$watch 'loading', (val) ->
        if (val)
          $(element).show()
        else
          $(element).hide()
  }

.config ($stateProvider, $urlRouterProvider, $locationProvider) ->
  $stateProvider
  
  .state 'spread',
    url: '/spread'
    templateUrl: 'templates/spread.html'
    controller: 'SpreadCtrl' 

  .state 'activity-unlock',
    url: '/activity-unlock'
    templateUrl: 'templates/activity-unlock.html'
    controller: 'ActivityUnlockCtrl'

  .state 'activity-liuyue',
    url: '/activity-liuyue'
    templateUrl: 'templates/activity-liuyue.html'
    controller: 'ActivityLiuYueCtrl'

  .state 'reward-record-liuyue',
    url: '/reward-record-liuyue'
    templateUrl: 'templates/reward-record-liuyue.html'
    controller: 'RewardRecordLiuyueCtrl'

  .state 'rewardRecord',
    url: '/rewardRecord'
    templateUrl: 'templates/rewardRecord.html'
    controller: 'RewardRecordCtrl' 

  .state 'accumulate-points',
    url: '/accumulate-points'
    templateUrl: 'templates/accumulate-points.html'
    controller: 'AccumulatePointsCtrl' 
  
  $urlRouterProvider.otherwise '/spread'
  return